import gugga.animations.MaskAnimationTypes;
import gugga.animations.MotionDirections;
import gugga.animations.MotionTypes;
import gugga.animations.PropertiesTweenAnimationType;
import gugga.animations.ScrollRectAnimation;

/**
 * @author Todor Kolev
 */
class gugga.animations.ScrollRectLinedAnimation extends ScrollRectAnimation 
{
	private var mLine : MovieClip;
	public function get Line() : MovieClip { return mLine; }
	public function set Line(aValue:MovieClip) : Void { mLine = aValue; }
	
	private var mLineToEdgeOffset : Number = 0;
	public function get LineToEdgeOffset() : Number { return mLineToEdgeOffset; }
	public function set LineToEdgeOffset(aValue:Number) : Void { mLineToEdgeOffset = aValue; }
	
	function ScrollRectLinedAnimation(aSubject : MovieClip, aType : MaskAnimationTypes, aDirection : MotionDirections, aMotionType : MotionTypes) 
	{
		super(aSubject, aType, aDirection, aMotionType);
	}
	
	private function onTweenUpdated(ev) : Void
	{
		super.onTweenUpdated(ev);
		
		if (mDirection == MotionDirections.Down ||
			mDirection == MotionDirections.DownLeft ||
			mDirection == MotionDirections.DownRight)
		{
			mLine._y = mSubject._y - mLine._height - mLineToEdgeOffset;
		}
		
		if (mDirection == MotionDirections.Up ||
			mDirection == MotionDirections.UpLeft ||
			mDirection == MotionDirections.UpRight)
		{
			mLine._y = mSubject._y + mScrollRect.height + mLine._height + mLineToEdgeOffset;
		}
		
		if (mDirection == MotionDirections.Right ||
			mDirection == MotionDirections.UpRight ||
			mDirection == MotionDirections.DownRight)
		{
			mLine._x = mSubject._x - mLine._width - mLineToEdgeOffset;
		}
		
		if (mDirection == MotionDirections.Left ||
			mDirection == MotionDirections.UpLeft ||
			mDirection == MotionDirections.DownLeft)
		{
			mLine._x = mSubject._x + mScrollRect.width + mLine._width + mLineToEdgeOffset;
		}
	}
	
	public static function createWipeInFrameAnimation(aDirection : MotionDirections, 
		aTarget : MovieClip, aTime : Number, aEasingType : Function) : ScrollRectLinedAnimation
	{
		var result : ScrollRectLinedAnimation = new ScrollRectLinedAnimation(aTarget, MaskAnimationTypes.Wipe,
			aDirection, MotionTypes.In);
		
		result.TweenType = PropertiesTweenAnimationType.FrameTween;
		applyAdditionalProperties(result, aTime, aEasingType);
		
		return result;
	}
	
	public static function createWipeOutFrameAnimation(aDirection : MotionDirections, 
		aTarget : MovieClip, aTime : Number, aEasingType : Function) : ScrollRectLinedAnimation
	{
		var result : ScrollRectLinedAnimation = new ScrollRectLinedAnimation(aTarget, MaskAnimationTypes.Wipe,
			aDirection, MotionTypes.Out);
		
		result.TweenType = PropertiesTweenAnimationType.FrameTween;
		applyAdditionalProperties(result, aTime, aEasingType);
		
		return result;
	}
	
	public static function createFlyInFrameAnimation(aDirection : MotionDirections, 
		aTarget : MovieClip, aTime : Number, aEasingType : Function) : ScrollRectLinedAnimation
	{
		var result : ScrollRectLinedAnimation = new ScrollRectLinedAnimation(aTarget, MaskAnimationTypes.Fly,
			aDirection, MotionTypes.In);
		
		result.TweenType = PropertiesTweenAnimationType.FrameTween;
		applyAdditionalProperties(result, aTime, aEasingType);
		
		return result;
	}
	
	public static function createFlyOutFrameAnimation(aDirection : MotionDirections, 
		aTarget : MovieClip, aTime : Number, aEasingType : Function) : ScrollRectLinedAnimation
	{
		var result : ScrollRectLinedAnimation = new ScrollRectLinedAnimation(aTarget, MaskAnimationTypes.Fly,
			aDirection, MotionTypes.Out);
		
		result.TweenType = PropertiesTweenAnimationType.FrameTween;
		applyAdditionalProperties(result, aTime, aEasingType);
		
		return result;
	}
	
	public static function createWipeInTimeAnimation(aDirection : MotionDirections, 
		aTarget : MovieClip, aTime : Number, aEasingType : Function) : ScrollRectLinedAnimation
	{
		var result : ScrollRectLinedAnimation = new ScrollRectLinedAnimation(aTarget, MaskAnimationTypes.Wipe,
			aDirection, MotionTypes.In);
		
		result.TweenType = PropertiesTweenAnimationType.TimeTween;
		applyAdditionalProperties(result, aTime, aEasingType);
		
		return result;
	}
	
	public static function createWipeOutTimeAnimation(aDirection : MotionDirections, 
		aTarget : MovieClip, aTime : Number, aEasingType : Function) : ScrollRectLinedAnimation
	{
		var result : ScrollRectLinedAnimation = new ScrollRectLinedAnimation(aTarget, MaskAnimationTypes.Wipe,
			aDirection, MotionTypes.Out);
		
		result.TweenType = PropertiesTweenAnimationType.TimeTween;
		applyAdditionalProperties(result, aTime, aEasingType);
		
		return result;
	}
	
	public static function createFlyInTimeAnimation(aDirection : MotionDirections, 
		aTarget : MovieClip, aTime : Number, aEasingType : Function) : ScrollRectLinedAnimation
	{
		var result : ScrollRectLinedAnimation = new ScrollRectLinedAnimation(aTarget, MaskAnimationTypes.Fly,
			aDirection, MotionTypes.In);
		
		result.TweenType = PropertiesTweenAnimationType.TimeTween;
		applyAdditionalProperties(result, aTime, aEasingType);
		
		return result;
	}
	
	public static function createFlyOutTimeAnimation(aDirection : MotionDirections, 
		aTarget : MovieClip, aTime : Number, aEasingType : Function) : ScrollRectLinedAnimation
	{
		var result : ScrollRectLinedAnimation = new ScrollRectLinedAnimation(aTarget, MaskAnimationTypes.Fly,
			aDirection, MotionTypes.Out);
		
		result.TweenType = PropertiesTweenAnimationType.TimeTween;
		applyAdditionalProperties(result, aTime, aEasingType);
		
		return result;
	}

}